﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.PreservedEntities.CUiUnpreservedEntitiesCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.PreservedObjects;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.PreservedEntities;

public sealed class CUiUnpreservedEntitiesCmd : TxButtonCommand
{
  private CApPreservedObjectsEnabler m_enabler;

  public CUiUnpreservedEntitiesCmd() => this.m_enabler = new CApPreservedObjectsEnabler(false);

  public virtual string Category => PreservedObjectsRes.CMD_CATEGORY;

  public virtual string Name => PreservedObjectsRes.UNPRES_CMD_NAME;

  public virtual string Tooltip => PreservedObjectsRes.UNPRES_CMD_TOOLTIP;

  public virtual string Bitmap => "Resources.UnPreserveEntity.bmp";

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("SetAsUnpreservedObjects");
  }

  public virtual string Description => PreservedObjectsRes.UNPRES_CMD_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Licensed => TxCommandLicenser.SetAsUnPreservedObjects;

  public virtual void Execute(object cmdParams)
  {
    string str = "";
    TxObjectList items = TxApplication.ActiveSelection.GetItems();
    if (((Collection<ITxObject>) items).Count >= 1)
    {
      TxApplication.ActiveUndoManager.StartTransaction();
      foreach (ITxDetailedRepresentation detailedRepresentation in (Collection<ITxObject>) items)
      {
        if (!detailedRepresentation.CanUnpreserved())
          str = $"{str}{((ITxObject) detailedRepresentation).Name}, ";
        else
          detailedRepresentation.Preserved = false;
      }
      if (((Collection<ITxObject>) items).Count == 1)
        TxApplication.ActiveSelection.SetItems(items);
      TxApplication.ActiveUndoManager.EndTransaction();
    }
    TxApplication.RefreshDisplay();
    if (str.Equals(string.Empty) || str.Length <= 2)
      return;
    int num = (int) MessageBox.Show(PreservedObjectsRes.UNPRES_CMD_READONLY_OBJS + str.Remove(str.Length - 2), PreservedObjectsRes.UNPRES_CMD_NAME);
  }
}
